<template>
  <van-search
    shape="round"
    placeholder="小区/写字楼/学校等"
    @focus="onSearch"
    @input="search"
    v-model="value"
  >
    <template #label>
      <span class="address-text" style="margin-right: 5px" @click="mapList">{{
        currentCity.name
      }}</span>
      <van-icon name="arrow-down" />
    </template>
  </van-search>
</template>

<script>
export default {
  data() {
    return {
      currentCity: JSON.parse(localStorage.getItem('currentCity')),
      value: '',
    }
  },
  // created() {
  //   this.currentCity = JSON.parse(localStorage.getItem('currentCity')) || {
  //     name: '长沙',
  //   }
  // },
  methods: {
    mapList() {
      this.$router.push('/mapList')
    },
    onSearch() {
      if (this.$route.path !== '/address/search') {
        this.$router.push('/address/search')
      }
    },
    search() {
      this.$emit('search', this.value)
    },
  },
}
</script>

<style>
</style>